<template>
  <!-- 搜索 -->
  <el-autocomplete
    :prefix-icon="imgUrl"
    v-model="state4"
    :fetch-suggestions="querySearchAsync"
    placeholder="请输入内容"
    @select="handleSelect"
    class="inputsearch"
  ></el-autocomplete>
</template>
<script>
export default {
  data() {
    return {
      restaurants: [],
      state4: "",
      timeout: null,
      imgUrl:require('../../common/images/search.png')
    };
  },
  watch: {},
  mounted() {},
  methods: {
    querySearchAsync(queryString, cb) {
      var list = [{}];
      this.$store.dispatch("user", queryString).then(data => {
        list = data;
        for (let i of data) {
          i.value = i.realName + i.username; //将想要展示的数据作为value
        }
        cb(list);
      });
    },
    handleSelect(item) {
      this.$emit("UserID", item.userId);
    }
  }
};
</script>
<style>
.inputsearch input{
  padding-right:30px;
}
</style>
